/**
 * 
 */
package com.wbcs.system.component.application.report;

import java.util.List;
import java.util.Map;

import com.jf.json.JbsfJsonFactory;
import com.wbcs.system.component.application.report.configbean.ColAndGroupDisplayBean;
import com.wbcs.system.component.application.report.configbean.ServerJsonServiceBean;
import com.wbcs.system.tags.component.AbsComponentTag;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wbcs.WbcsFacade;
import com.wbcs.config.component.IComponentConfigBean;
import com.wbcs.config.component.application.report.ReportBean;
import com.wbcs.config.xml.XmlElementBean;
import com.wbcs.exception.WbcsConfigLoadingException;
import com.wbcs.system.CacheDataBean;
import com.wbcs.system.ReportRequest;
import com.wbcs.system.component.application.report.abstractreport.AbsRequireChainReportType;
import com.wbcs.system.component.container.AbsContainerType;
import com.wbcs.system.function.FuncAssistant;
import com.wbcs.system.function.FuncContextBean;
import com.wbcs.system.function.IFunc;
import com.wbcs.system.function.IFuncDo;
import com.wbcs.util.Consts;
import com.wbcs.util.Consts_Private;
import com.wbcs.util.Tools;

/**
 * 专门提供后台Json数据返回业务处理的服务报表类型
 * 建议和具有Ajax请求的前台组件配合使用
 * 可以作为chain类型报表业务处理链条的最后结果返回节点
 * @author hawkfly
 */
public class ServerJsonServiceType extends AbsRequireChainReportType{
	
	public ServerJsonServiceType(AbsContainerType parentContainerType,
			IComponentConfigBean comCfgBean, ReportRequest rrequest) {
		super(parentContainerType, comCfgBean, rrequest);
		// TODO Auto-generated constructor stub
		
	}
	
	public void init(){
		super.init();
		
	}

	@Override
	public void displayOnPage(AbsComponentTag displayTag)
	{
		//组织Json
		if(requireFuncObj != null){
			super.displayOnPage(displayTag);
		}

		if(jsonBean == null)doSelect();
		String jsonLstReportData = JbsfJsonFactory.me().getJson().toJson(jsonBean);
		rrequest.getPagebean().setPageJsonStr(jsonLstReportData);
		//wresponse.println(jsonLstReportData,true);
	}

	@Override
	public String getReportFamily()
    {
        return Consts_Private.REPORT_FAMILY_JSON;
    }
	@Override
	public void loadReportData(boolean shouldInvokePostaction){
		
		CacheDataBean cdb = this.rrequest.getCdb(this.rbean.getId());
		String pageno = this.rrequest.getRequest().getParameter("_PAGENO");
		try{
			if(pageno != null && !"".equals(pageno)){
				cdb.setPageno(Integer.parseInt(pageno));
			}
		}catch(Exception e){
		}
		super.loadReportData(shouldInvokePostaction);
	}
}
